import { useChatStore } from '../stores/chat';

export function generateMockUsersData() {
  // 模拟用户数据
  const mockUsers = [];
  const statusList = ['active', 'waiting', 'closed'];
  const lastMsgList = [
    '您好,请问有什么可以帮您?',
    '我想咨询一个问题',
    '好的,我明白了',
    '谢谢,再见',
    '请问这个怎么操作?',
    '可以帮我看看这个问题吗?'
  ];
  const familyNames = ['张', '李', '王', '赵', '刘', '陈', '杨', '黄', '周', '吴'];
  const givenNames = ['伟', '芳', '娜', '秀英', '敏', '静', '丽', '强', '磊', '洋'];

  for (let i = 1; i <= 20; i++) {
    const randomFamilyName = familyNames[Math.floor(Math.random() * familyNames.length)];
    const randomGivenName = givenNames[Math.floor(Math.random() * givenNames.length)];
    
    mockUsers.push({
      id: `user${i}`,
      name: `${randomFamilyName}${randomGivenName}`,
      avatar: `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40"><rect width="100%" height="100%" fill="#${Math.floor(Math.random()*16777215).toString(16).padStart(6, '0')}"/><text x="50%" y="50%" dy=".3em" fill="white" text-anchor="middle" font-size="20">${randomFamilyName[0]}</text></svg>`)}`,
      status: statusList[Math.floor(Math.random() * statusList.length)],
      last_chat_msg: lastMsgList[Math.floor(Math.random() * lastMsgList.length)],
      last_chat_time: Date.now() - 1000 * 60 * Math.floor(Math.random() * 60), // 随机生成60分钟内的时间
      unread_count: Math.floor(Math.random() * 10),
      created_at: Date.now() - 1000 * 60 * Math.floor(Math.random() * 60 * 24 * 30) // 随机生成30天内的时间
    });
  }

  // 将模拟用户数据写入store
  const chatStore = useChatStore();
  console.log(chatStore);
  mockUsers.forEach(user => {
    chatStore.addUser(user);
  });
  
  return mockUsers;
}